#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "T9Trie.h"

using namespace std;


std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
    std::stringstream ss(s);
    std::string item;
    while(getline(ss, item, delim) || getline(ss, item, '\0')) {
        elems.push_back(item);
    }
    return elems;
}


std::vector<std::string> split(const std::string &s, char delim) {
    std::vector<std::string> elems;
    return split(s, delim, elems);
}
void readFile(string filename, vector<string>& dict, vector<int>& freq) {
	ifstream file(filename.c_str());
        if (file.is_open()) {
                string line;
                while (file.good()) {
                        getline(file, line);
                        if (line.length()>0) {
                                vector<string> args=split(line, ' ');
								dict.push_back(args[0]);
								freq.push_back(atoi(args[1].c_str()));
                        }
                }
                file.close();
        }
}


int main() {
	vector<string> dict;
	vector<int> freq;
	readFile("input.txt", dict, freq);
	/*for (int i=0; i<dict.size(); i++) {
		cout<<dict[i]<<" || "<<freq[i]<<endl;  
	}*/

	T9Trie t9=T9Trie(dict, freq);
	t9.buildAutomat();

	t9.search();
	system("pause");
	return 0;
}